<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page deferredSyntaxAllowedAsLiteral="true" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/style.css"/>
    <script type="text/javascript" src="./Js/jquery.js"></script>
    <script type="text/javascript" src="./Js/bootstrap.js"></script>
    <script type="text/javascript" src="./Js/ckform.js"></script>
    <script type="text/javascript" src="./Js/common.js"></script>
    <script type="text/javascript" charset="utf-8" src="./BDUeditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="./BDUeditor/ueditor.all.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="./BDUeditor/lang/zh-cn/zh-cn.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }

    </style>

</head>
<body>
<form action="" method="post">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td class="tableleft">学校名称</td>
            <td><input type="text" id="schoolname" name="schoolname"/></td>
        </tr>
        <tr>
            <td class="tableleft">地址</td>
            <td><input type="text" style="width: 500px;" id="address" name="address"/></td>
        </tr>
        <tr>
            <td class="tableleft">需要援助</td>
            <td>
                <input name="isneed" type="radio" value="1" checked/> 是
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input name="isneed" type="radio" value="2"/> 否
            </td>
        </tr>
        <tr>
            <td class="tableleft">前往援助</td>
            <td>
                <input type="radio" name="ishelp" value="1" checked/> 是
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="ishelp" value="2"/> 否
            </td>
        </tr>
        <tr>
            <td class="tableleft">详细信息</td>
            <td>
                <div>
                    <%--		    	<textarea class="uEditorCustom" id="editor" rows="5" cols="5"></textarea>--%>
                    <script id="info" name="info" type="text/plain" style="width:1024px;height:200px;"></script>
                </div>
            </td>
        </tr>
        <tr>
            <td class="tableleft">援藏历史</td>
            <td>
                <div>
                    <script id="history" name="history" type="text/plain" style="width:1024px;height:200px;"></script>
                    <%--                <textarea style= "overflow:hidden; resize:none; " rows="10" cols="20"></textarea>--%>
                </div>
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="button" id="submit-button" class="btn btn-primary">保存</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
    $("#backid").click(function () {
        window.location.href = "/school/list";
    })
</script>
<script type="text/javascript">
    var info = UE.getEditor("info", {
        autoFloatEnabled: false
    });
    var history = UE.getEditor("history", {
        autoFloatEnabled: false
    });
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor', {
        autoFloatEnabled: false//是否保持toolbar位置不懂，默认为true
    });

    function isFocus(e) {
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }

    function setblur(e) {
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }

    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }

    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }

    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }

    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }

    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }

    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }

    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }

    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }

    function setFocus() {
        UE.getEditor('editor').focus();
    }

    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }

    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }

    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData() {
        alert(UE.getEditor('editor').execCommand("getlocaldata"));
    }

    function clearLocalData() {
        UE.getEditor('editor').execCommand("clearlocaldata");
        alert("已清空草稿箱")
    }
</script>

<script type="text/javascript">
    $("#submit-button").click(function () {
        var schoolname = $("#schoolname").val();
        var address = $("#address").val();
        var isneed = $('input[name="isneed"]:checked').val();
        var ishelp = $('input[name="ishelp"]:checked').val();
        var param = "schoolname=" + schoolname + "&address=" + address + "&isneed=" + isneed +"&operator=${username}" + "&ishelp=" + ishelp + "&intro=" + UE.getEditor("info").getContent() + "&hisroty=" + UE.getEditor("history").getContent();
        $.ajax({
            url: "/school/add",
            type: "post",
            async: true,
            data: param,
            success: function (res) {
                if (res.success) {
                    alert("添加成功！")
                    window.location.href = "/school/list";
                } else {
                    alert(res.message);
                }
            }, error: function (e) {
                alert(e)
            }
        });
    })
</script>
</html>